import mysql.connector
#省内生源地分布


def fromplaceRatio():
    mydb = mysql.connector.connect(
        host="124.222.244.117",  # 数据库主机地址
        user="zrgj9",  # 用户名
        passwd="zrgj9",  # 密码
        database="zrgj9"
    )
    mycursor = mydb.cursor()
    sql = """SELECT stuNation,
            count(stuid) 
            from student
            where register = 1
            group by stuNation"""
    try:
        mycursor.execute(sql)
        data = mycursor.fetchall()
        mydb.commit()
    except:
        mydb.rollback()
    mydb.close()
    # sum = 0
    for i in range(len(data)):
        data[i] = list(data[i])
        # sum+=data[i][1]
    data1 = []
    for i in range(len(data)):
        dict = {}
        dict["x"] = data[i][1]
        # z = data[i][1]/sum
        # dict["percent"] = round(z*100,2)
        dict["y"] = data[i][0]
        data1.append(dict)
    return data1
